using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ImageProcessing
{
    public partial class PixelOperationsAdvancedGraph : Form
    {

        Bitmap srcBmp, distBmp;
        float zoom = 1.0f;
        Channel channel;

        public PixelOperationsAdvancedGraph(DImage i)
        {
            InitializeComponent();
            srcBmp = i.ImageBitmap;
            imagePanel1.Image = srcBmp;
            channel = Channel.All;
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            ToolStripButton b = (ToolStripButton)sender;
            if (b.Text == "Select")
            {
                imagePanel1.DoSelection = true;
                b.Text = "Deselect";
            }
            else
            {
                b.Text = "Select";
                imagePanel1.DoSelection = false;
                if (srcBmp != null)
                    imagePanel1.SelectedArea = new Rectangle(0, 0, 0, 0);
            }
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            zoom += 0.1f;
            imagePanel1.Zoom = zoom;
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            zoom -= 0.1f;
            imagePanel1.Zoom = zoom;
        }

        private void toolStripButton22_Click(object sender, EventArgs e)
        {
            zoom += 0.1f;
            imagePanel2.Zoom = zoom;
        }

        private void toolStripButton32_Click(object sender, EventArgs e)
        {
            zoom -= 0.1f;
            imagePanel2.Zoom = zoom;
        }


        private void imageCurve1_LevelChangedEvent(object sender, LevelChangedEventArgs e)
        {
            distBmp = ImageCurve.ChangeChannelLevel(srcBmp, imagePanel1.SelectedArea, channel, e.LevelValue);
            imagePanel2.Image = distBmp;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            channel = (Channel)comboBox1.SelectedIndex;
        }

        private void imagePanel2_Load(object sender, EventArgs e)
        {

        }

        private void BtnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void BtnOk_Click(object sender, EventArgs e)
        {
            Main.ImageList[Main.CurrImage].UpdateImage(distBmp);
            this.Close();
        }
    }
}